]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
networkAgent: Use libnm for plugin loading
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 3 Nov 2016 14:25:49 +0000 (15:25 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Fri, 13 Apr 2018 14:04:55 +0000 (14:04 +0000)
After the networking code has been ported to libnm, we can use its
API for loading VPN plugins instead of rolling our own ...

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/39

js/ui/components/networkAgent.js

index c51e53eba42c37a120bb6820e50bf34c76cb0f3e..75f42037308ae477618b33e4f3491569f56ec8b4 100644 (file)
@@ -765,57 +765,29 @@ var NetworkAgent = new Lang.Class({
         this._vpnCacheBuilt = true;
         this._vpnBinaries = { };
 
-        try {
-            let fileEnum = this._pluginDir.enumerate_children('standard::name', Gio.FileQueryInfoFlags.NONE, null);
-            let info;
+        NM.VpnPluginInfo.list_load().forEach(plugin => {
+            let service = plugin.get_service();
+            let fileName = plugin.get_auth_dialog();
+            let supportsHints = plugin.supports_hints();
+            let externalUIMode = false;
+
+            let prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
+            if (prop) {
+                prop = prop.trim().toLowerCase();
+                externalUIMode = ['true', 'yes', 'on', '1'].includes(prop);
+            }
 
-            while ((info = fileEnum.next_file(null))) {
-                let name = info.get_name();
-                if (name.substr(-5) != '.name')
-                    continue;
+            if (GLib.file_test(fileName, GLib.FileTest.IS_EXECUTABLE)) {
+                let binary = { fileName, externalUIMode, supportsHints };
+                this._vpnBinaries[service] = binary;
 
-                try {
-                    let keyfile = new GLib.KeyFile();
-                    keyfile.load_from_file(this._pluginDir.get_child(name).get_path(), GLib.KeyFileFlags.NONE);
-                    let service = keyfile.get_string('VPN Connection', 'service');
-                    let binary = keyfile.get_string('GNOME', 'auth-dialog');
-                    let externalUIMode = false;
-                    let hints = false;
-
-                    try {
-                        externalUIMode = keyfile.get_boolean('GNOME', 'supports-external-ui-mode');
-                    } catch(e) { } // ignore errors if key does not exist
-
-                    try {
-                        hints = keyfile.get_boolean('GNOME', 'supports-hints');
-                    } catch(e) { } // ignore errors if key does not exist
-
-                    let path = binary;
-                    if (!GLib.path_is_absolute(path)) {
-                        path = GLib.build_filenamev([Config.LIBEXECDIR, path]);
-                    }
-
-                    if (GLib.file_test(path, GLib.FileTest.IS_EXECUTABLE)) {
-                        this._vpnBinaries[service] = { fileName: path, externalUIMode: externalUIMode, supportsHints: hints };
-                        try {
-                            let aliases = keyfile.get_string_list('VPN Connection', 'aliases');
-
-                            for (let alias of aliases) {
-                                this._vpnBinaries[alias] = { fileName: path, externalUIMode: externalUIMode, supportsHints: hints };
-                            }
-                        } catch(e) { } // ignore errors if key does not exist
-                    } else {
-                        throw new Error('VPN plugin at %s is not executable'.format(path));
-                    }
-                } catch(e) {
-                    log('Error \'%s\' while processing VPN keyfile \'%s\''.
-                        format(e.message, this._pluginDir.get_child(name).get_path()));
-                    continue;
-                }
+                plugin.get_aliases().forEach(alias => {
+                    this._vpnBinaries[alias] = binary;
+                });
+            } else {
+                log('VPN plugin at %s is not executable'.format(fileName));
             }
-        } catch(e) {
-            logError(e, 'error while enumerating VPN auth helpers');
-        }
+        });
     }
 });
 var Component = NetworkAgent;